<template>
    <div>
         <h2>登录页面</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">账号</td>
                    <td><input type="text" v-model="info.userName"></td>
                </tr>
                 <tr>
                    <td align="right">密码</td>
                    <td><input type="text" v-model="info.userPwd"></td>
                </tr>
                 <tr>
                    <td align="right"></td>
                    <td><input type="button" value="登录" class="btn btn-success" @click="login"></td>
                </tr>
            </tbody>
        </table>
        {{ info }}
    </div>
</template>

<script setup lang="ts">
import{ref,reactive} from 'vue'
import axios from 'axios';
import{useRouter} from 'vue-router';
const router=useRouter();

let info=ref({
    userName:'',
    userPwd:'',
})
const login=()=>{

   if(info.value.userName==''){
    alert("账号不能为空");
    return;
   }
   if(info.value.userPwd==''){
    alert("密码不能为空");
    return;
   }
   axios({
    url:'/api/Values/Login',
    method:'post',
    params:info.value,
   })
   .then((res)=>{
        console.log(res);
        if(res.data==-1)
    {
        alert("账号不存在,请联系管理员");
        return;
    }
    if(res.data==-2){
        alert("密码错误");
        return;
    }
    alert("登录成功");
    router.push('/memberAdd')
   })
   .catch((err)=>{
    console.log(err);
   })

}

</script>

<style scoped>

</style>    